<template>
  <div class="right-list" ref="rightListWrap">
    <!-- 空的div，里面放better--scroll -->
    <div>
      <!-- 当type=1为推荐时，头部有图片 -->
      <div class="img" v-if="type=='1'">
        <img :src="img" alt />
      </div>

      <div class="classify-list" v-for="item in 5" :key="item">
        <P class="title">热门推荐</P>
        <ul>
          <li v-for="(item,index) in classifyList" :key="index" @click="toGoodsList">
            <img :src="item.imgUrl" alt />
            <span>旅行箱</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import Img from "../../../assets/image/classify-recommend.png";
//引入better-scroll
import BScroll from 'better-scroll';

import { createNamespacedHelpers } from "vuex";//加上命名空间辅助函数

const { mapState } = createNamespacedHelpers("classifyList");//需要那个辅助函数，就解构出来

export default {
  data() {
    return {
      img: Img,
  
    };
  },
  computed: {
    ...mapState(["classifyList", "type"]),
    // type() {
    //   return this.$store.state.classifyList.type;
    // },
    // classifyList() {
    //   return this.$store.state.classifyList.classifyList;
    // }
  },
  mounted() {
    this.$store.dispatch('classifyList/getClassifyList',{
      type: '1'
    }),
    //  this.bScroll=new BScroll(this.$refs.rightListWrap,{
    //   //滚动部分允许点击
    //   click:true,
    //   //允许上拉加载
    //   pullUpLoad:true
    // })
     //this.$nextTick是在所有的dom全部渲染完以后要做的事情
           this.$nextTick(()=>{
               // 创建实例，第一个参数是操作的元素， 第二个是传递的参数
                let bScroll=new BScroll(this.$refs.rightListWrap,{
               //滚动部分允许点击
               click:true,
               //允许上拉加载
               pullUpLoad:true
           })
            //上拉加载，监听pullingUp方法
            bScroll.on('pullingUp',()=>{
               
                bScroll.finishPullUp()//加载完成
               
            })

           })
    
  },

  methods: {
    toGoodsList() {
      this.$router.push("/goodslist");
    },    
  },
};
</script>
<style lang="stylus" scoped>
.right-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;

  .img {
    width: 281px;
    height: 103px;
    margin: 12px auto 22px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .classify-list {
    margin: 12px 10px 0;

    p {
      font-size: 14px;
      color: #2d2d2d;
      margin: 4px 12px 0 0;
      font-weight: 500;  
      font-family: PingFang SC;

    }

    ul {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      margin-top: 16px;

      li {
        width: 70px;
        height: 100px;
        margin-bottom: 30px;
        margin-right: 30px;

        img {
          width: 70px;
          height: 67px;
        }

        span {
          display: block;
          font-size: 12px;
          color: #333;
          margin-top: 12px;
          text-align: center;          
          font-family: PingFang SC;
          font-weight: 500;
        }
      }

      li:nth-child(3n) {
        margin-right: 10px;
      }
    }
  }
}
</style>